stylecontext: Keep track of children
authorBenjamin Otte <otte@redhat.com>
Tue, 20 Mar 2012 01:06:00 +0000 (02:06 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 17 Apr 2012 06:59:09 +0000 (08:59 +0200)
gtk/gtkstylecontext.c

index 4e8e2827a3d27894ae0cf6be0ddaefbd5c2d10e4..6bbc6d613726bee081e03b80f60948e5acc5a034 100644 (file)
@@ -361,6 +361,7 @@ struct _GtkStyleContextPrivate
   GtkStyleCascade *cascade;
 
   GtkStyleContext *parent;
+  GSList *children;
   GtkWidget *widget;            
   GtkWidgetPath *widget_path;
   GHashTable *style_data;
@@ -806,6 +807,9 @@ gtk_style_context_finalize (GObject *object)
   style_context = GTK_STYLE_CONTEXT (object);
   priv = style_context->priv;
 
+  /* children hold a reference to us */
+  g_assert (priv->children == NULL);
+
   gtk_style_context_set_parent (style_context, NULL);
 
   if (priv->widget_path)
@@ -1580,10 +1584,16 @@ gtk_style_context_set_parent (GtkStyleContext *context,
     return;
 
   if (parent)
-    g_object_ref (parent);
+    {
+      parent->priv->children = g_slist_prepend (parent->priv->children, context);
+      g_object_ref (parent);
+    }
 
   if (priv->parent)
-    g_object_unref (priv->parent);
+    {
+      priv->parent->priv->children = g_slist_remove (priv->parent->priv->children, context);
+      g_object_unref (priv->parent);
+    }
 
   priv->parent = parent;